package com.ac.api.process_line.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ac.api.process_line.entity.ProcessLine;
import com.ac.api.process_line.dao.ProcessLineMapper;
import com.ac.api.process_line.service.ProcessLineService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 生产线信息表 服务实现类
 * </p>
 *
 * @author dc
 * @since 2025-06-11
 */
@Service
public class ProcessLineServiceImpl extends ServiceImpl<ProcessLineMapper, ProcessLine> implements ProcessLineService {

    @Override
    public List<ProcessLine> list(ProcessLine example) {
        return this.list(buildWrapper(example));
    }

    @Override
    public IPage<ProcessLine> page(ProcessLine example, IPage page) {
        return this.page(page,buildWrapper(example));
    }

    @Override
    public void addToProduction(Integer productionLineId,
                                LocalDateTime edtime) {
        this.update(new ProcessLine().setStatus("生产中")
                        .setEndTime(null)
                .setStartTime(LocalDateTime.now())
                ,new QueryWrapper<ProcessLine>().eq("line_id",productionLineId));
    }

    @Override
    public List<ProcessLine> running() {//获取生产中的或者加急中的生产线
        return this.list(new QueryWrapper<ProcessLine>().eq("status","生产中").or().eq("status","加急中"));
    }

    /**
     * 构建查询
     *
     * @param example
     * @return
     */
    private QueryWrapper<ProcessLine> buildWrapper(ProcessLine example) {
        QueryWrapper<ProcessLine> wrapper     = new QueryWrapper<>();
        return wrapper;
    }

}
